package com.course.redisson.controller;

import cn.hutool.core.util.RandomUtil;
import com.course.common.response.BaseResponse;
import com.course.common.response.StatusCode;
import com.course.model.entity.redisson.UserOrder;
import com.course.model.util.ValidatorUtil;
import com.course.redisson.dto.UserOrderDto;
import com.course.redisson.service.RMap.OrderService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @PROJECT_NAME: course
 * @DESCRIPTION:
 * @Author: 涂玄武
 * @DATE: 2021/6/7 10:49
 */
@RestController
@RequestMapping("order")
public class OrderController extends BaseController{

    public static final String BUSINESS_NAME = "用户订单";

    @Resource
    private OrderService orderService;

    /**
     * 下订单
     * @param order
     * @param result
     * @return
     */
    @RequestMapping(value = "push")
    public BaseResponse pushOrderV2(@RequestBody @Validated UserOrderDto order, BindingResult result) {
        //参数检核
        ValidatorUtil.checkResult(result);
        BaseResponse response = new BaseResponse().sucess();
        long ttl = RandomUtil.getRandom().nextLong(5, 10);
        response.setData(orderService.addOrder(order,ttl));
        return response;
    }
}
